/**
 * 
 */
package tech.abing.spider.task.pageprocessor.amac;

import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import tech.abing.spider.component.PageProcessor;
import tech.abing.spider.component.PageScript;
import tech.abing.spider.model.Proccessable;
import tech.abing.spider.page.OkPage;
import tech.abing.spider.page.Page;
import tech.abing.spider.request.BasicRequest;
import tech.abing.spider.request.StartContext;
import tech.abing.spider.task.model.amac.AdminLicenseDetailEntity;
import tech.abing.spider.util.StringUtils;
import tech.abing.spider.util.UuIdPublic;

/**
 * 类说明
 * @author HUNING
 * @since 2017-11-29
 * 
 */
public class AdminLicenseDetailProcessor implements PageProcessor{

	private static Logger logger = Logger.getLogger(AdminLicenseDetailProcessor.class);
	@Override
	public PageScript getJavaScript() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Pattern getNormalContain() {
		return null;
	}
	@Override
	public void process(OkPage page, StartContext context, List<BasicRequest> queue, List<Proccessable> objectContainer)
			throws Exception {
		Document doc = Jsoup.parse(page.getContent());
		AdminLicenseDetailEntity detail = new AdminLicenseDetailEntity();
		
		String url = page.getRequest().getUrl();
		
		Element ele = doc.select("#gkml > div.main").first();
		detail.setName(ele.select("#headContainer > tbody > tr:nth-child(3) > td > #lTitle").text());
		detail.setIndexNo(ele.select("#headContainer > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(1)").text());
		detail.setClassify(ele.select("#lSubcat").text());
		detail.setPushDate(ele.select("#headContainer > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > span").text());
		detail.setCreateTime(new Date());
		detail.setNumber(ele.select("#headContainer > tbody > tr:nth-child(4) > td > table > tbody > tr > td:nth-child(1) > span").text());
		detail.setPushSubject(ele.select("#headContainer > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(1) > span").text());
		detail.setTitle(ele.select("#headContainer > tbody > tr:nth-child(4) > td > table > tbody > tr > td:nth-child(2) > span").text());
		detail.setId(UuIdPublic.timeStrongID(5));
		detail.setContent(ele.select("#ContentRegion").text());
		detail.setLinkUrl(url);
		objectContainer.add(detail);
	}

	@Override
	public void processErrorPage(Page page, StartContext context, List<Proccessable> objectContainer) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
